package com.tuzhi.testjpa.jpa1;

import com.tuzhi.base.jpa.repository.BaseEnity;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

@Entity
@EntityListeners(AuditingEntityListener.class)
@DynamicInsert
@DynamicUpdate
@Table(name = "sys_user", schema = "tuzhi", catalog = "")
public class SysUserEntity extends BaseEnity {
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Id
    @Column(name = "id", nullable = false)
    private Long id;
    @Basic
    @Column(name = "username", nullable = false, length = 64)
    private String username;
    @Basic
    @Column(name = "nickname", nullable = true, length = 64)
    private String nickname;
    @Basic
    @Column(name = "password", nullable = false, length = 64)
    private String password;
    @Basic
    @Column(name = "salt", nullable = false, length = 16)
    private String salt;
//    @Basic
//    @Column(name = "dept_id", nullable = true)
//    private Long deptId;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "dept_id", referencedColumnName = "id")
    private SysDeptEntity sysDeptEntity;


    @Basic
    @Column(name = "picture", nullable = true, length = 255)
    private String picture;
    @Basic
    @Column(name = "sex", nullable = false)
    private Integer sex = 0;
    @Basic
    @Column(name = "email", nullable = true, length = 128)
    private String email;
    @Basic
    @Column(name = "phone", nullable = true, length = 32)
    private String phone;
    @Basic
    @Column(name = "remark", nullable = true, length = 128)
    private String remark;
    @Basic
    @CreatedDate
    @Column(name = "create_date", updatable = false)
    private Date createDate;
    @Basic
    @LastModifiedDate
    @Column(name = "update_date")
    private Date updateDate;
    @Basic
    @Column(name = "status", nullable = false)
    private Integer status = 0;

    @ManyToMany(targetEntity = SysRoleEntity.class)
    @JoinTable(name = "sys_user_role",
            // joinColumns,当前对象在中间表中的外键,
            // name="当前表的外键的名字（可随便取）“
            // referencedColumnName=“参照该表的主键”
            joinColumns = {@JoinColumn(name = "user_id", referencedColumnName = "id")},
            //inverseJoinColumns :对方对象在中间表的外键
            inverseJoinColumns = {@JoinColumn(name = "role_id", referencedColumnName = "id")}
    )
    private Set<SysRoleEntity> roles = new HashSet<>();


    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getSalt() {
        return salt;
    }

    public void setSalt(String salt) {
        this.salt = salt;
    }

//    public Long getDeptId() {
//        return deptId;
//    }
//
//    public void setDeptId(Long deptId) {
//        this.deptId = deptId;
//    }

    public String getPicture() {
        return picture;
    }

    public void setPicture(String picture) {
        this.picture = picture;
    }

    public Integer getSex() {
        return sex;
    }

    public void setSex(Integer sex) {
        this.sex = sex;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public Date getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Set<SysRoleEntity> getRoles() {
        return roles;
    }

    public void setRoles(Set<SysRoleEntity> roles) {
        this.roles = roles;
    }
}
